#include "SimpleWindow.h"

#include "Widgets/Window.h"

#include "Widgets/Editor/WindowButtons.h"
#include "Widgets/Editor/WindowResizeble.h"
#include "Widgets/Editor/DragWindowArea.h"

#include "Asset/EngineDefaultPackage.h"

#include "Widgets/ImageWidget.h"
#include "Widgets/TextWidget.h"

RWidgetPtr WH::AddCommonWidgets(RWindow *Window, bool bAddResizeArea)
{
    auto Background=NewWidget<RRectangleWidget>(Window->GetRootWidget());
    Background->Anchor.Fill(Window->GetRootWidget());
    Background->FillColor=SColor::FromHexRGB(0x222222);

    float TitleHeight=35.f;

    auto Dragable= NewWidget<RMouseDragWindowArea>(Window->GetRootWidget());
    Dragable->Anchor.HorizontalFill(Window->GetRootWidget());
    Dragable->Height=TitleHeight;

    auto Icon=NewWidget<RImageWidget>(Window->GetRootWidget());
    Icon->Image=REngineDefaultPackage::Get()->GetEngineIcon();
    Icon->Width=TitleHeight;
    Icon->Height=TitleHeight;

    auto Title=NewWidget<RTextWidget>(Window->GetRootWidget());
    Title->Text=Window->GetWindowTitle();
    Title->Anchor.LeftReference=Icon;
    Title->Anchor.LeftReferenceEdge=EHorizontalWidgetEdge::Right;
    Title->Anchor.LeftOffset=5;
    Title->Height=TitleHeight;
    Title->Width=300;
    Title->VerticalAlignment=ETextVerticalAlignment::Center;

    auto Buttons=NewWidget<RWindowButtons>(Window->GetRootWidget());
    Buttons->Anchor.RightReference=Window->GetRootWidget();

    //resizable 
    auto Resizable= NewWidget<RWindowResizeble>(Window->GetRootWidget());
    Resizable->Anchor.Fill(Window->GetRootWidget());

    auto UserContainer=NewWidget<RWidget>(Window->GetRootWidget());
    UserContainer->Anchor.LeftReference=Window->GetRootWidget();
    UserContainer->Anchor.LeftOffset=2;
    UserContainer->Anchor.RightReference=Window->GetRootWidget();
    UserContainer->Anchor.RightOffset=2;
    
    UserContainer->Anchor.TopReference=Window->GetRootWidget();
    UserContainer->Anchor.TopOffset=TitleHeight+2;
    UserContainer->Anchor.BottomReference=Window->GetRootWidget();
    UserContainer->Anchor.BottomOffset=2;

    return UserContainer;
}
